/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.model.Customer;
import com.startup.musicstore.model.Orders;
import com.startup.musicstore.services.UnpaidStatusService;
import com.startup.musicstore.services.crud.CustomerCrudService;
import com.startup.musicstore.services.crud.OrdersCrudService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author linda
 */
@Service("unpaidStatusService")
@Transactional
public class UnpaidStatusServiceImpl implements UnpaidStatusService{

    @Autowired
    private CustomerCrudService customerCrudService;
    
    @Autowired
    private OrdersCrudService ordersCrudService;
    
    @Override
    public List<Orders> getUnpaidOrders() {
        List<Orders> unpaidOrders = new ArrayList<Orders>();
        List<Orders> orders = ordersCrudService.findAll();
        for(Orders order : orders)
        {
            if(order.getCustomerInvoice().getInvoiceStatus().equalsIgnoreCase("UNPAID"));
            {
                unpaidOrders.add(order);
            }
        }
        
     
        return unpaidOrders;
    }

    @Override
    public List<Customer> getUnpaidCustomers() {
        List<Customer> unpaidCustomers = new ArrayList<Customer>();
        
        List<Customer> customers = customerCrudService.findAll();
        for(int i=0; i< customers.size(); i++)
        {
            List<Orders> ords = customers.get(i).getOrders();
            for(int j=0; j<ords.size(); j++)
            {
                if(ords.get(j).getCustomerInvoice().getInvoiceStatus().equalsIgnoreCase("UNPAID"))
                {
                    unpaidCustomers.add(customers.get(i));
                }
            }
        }
        
        return unpaidCustomers;  
    }
    
}
